<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增分类信息')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-classification-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">分类名称：</label>
                <div class="col-sm-8">
                    <input name="className" class="form-control" type="text">
                </div>
            </div>
            <!-- <div class="form-group">    
                <label class="col-sm-3 control-label">分类类型：</label>
                <div class="col-sm-8">
                    <input name="classType" class="form-control" type="text">
                </div>
            </div> -->
            <div class="form-group">    
                <label class="col-sm-3 control-label">分类类型 ：</label>
                <div class="col-sm-9">
				    <label class="radio-box">
				        <input type="radio" checked="true" value="1" id="optionsRadios1" name="classType">首页分类
				    </label>
				    <label class="radio-box">
				        <input type="radio" value="2" id="optionsRadios2" name="classType">书籍分类
				    </label>
				</div>
            </div>
            <!-- <div class="form-group">    
                <label class="col-sm-3 control-label">分类的图片地址：</label>
                <div class="col-sm-8">
                    <input name="classPictureUrl" class="form-control" type="text">
                </div>
            </div> -->
            <div class="form-group">    
                <label class="col-sm-3 control-label">排序：</label>
                <div class="col-sm-8">
                    <input name="ord" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">图片上传：</label>
                <div class="col-sm-8">
                    <input name="url" class="form-control" type="file"  onchange="uploadFile('url')">
                    <input id="classPictureUrl" name="classPictureUrl" class="form-control" type="hidden">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/classification"
        $("#form-classification-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-classification-add').serialize());
            }
        }
        
        function uploadFile(filePath) {
            var formData = new FormData();
            if ($("input[name='" + filePath + "']")[0].files[0] == null) {
                $.modal.alertWarning("请先选择文件路径");
                return false;
            }
            formData.append('file', $("input[name='" + filePath + "']")[0].files[0]);
            $.ajax({
            	url: ctx + "common/upload",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function (result) {
                	if (result.code == web_status.SUCCESS) {
                		$("#classPictureUrl").val(result.url);
					} else {
						$.modal.alertError(result.msg);
					}
                    
                }
            });
        }
    </script>
</body>
</html>